//
//  USAlertTipBar.m
//  us
//
//  Created by karry on 2025/4/14.
//

#import "USAlertTipBar.h"

@interface USAlertTipBar()

@property (nonatomic,strong)UIView *m_v0;

@property (nonatomic,strong)UIView *m_v1;

@end

@implementation USAlertTipBar

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _style = USAlertTipBarStyle0;
        [self setupView];
    }
    return self;
}

- (void)setupView{
    
    self.backgroundColor = [UIColor mi_1_color];
    
    self.titleLab = [UILabel new];
    self.titleLab.textAlignment = NSTextAlignmentLeft;
    self.titleLab.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
    self.titleLab.textColor = UIColor.blackColor;
    [self addSubview:self.titleLab];
    
    self.subLab = [UILabel new];
    self.subLab.textAlignment = NSTextAlignmentRight;
    self.subLab.font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
    self.subLab.textColor = UIColor.blackColor;
    [self addSubview:self.subLab];
    
    self.m_v0 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [self addSubview:self.m_v0];
    
    self.m_v1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];;
    [self addSubview:self.m_v1];
    
    self.color = [UIColor us_orangeColor];
}

- (void)setColor:(UIColor *)color{
    _color = color;
    
    self.m_v0.backgroundColor = color;
    self.m_v1.backgroundColor = color;
    
}

- (void)setStyle:(USAlertTipBarStyle)style{
    _style = style;
    
    if (style == USAlertTipBarStyleDefault) {
        self.m_v0.hidden = NO;
        self.m_v1.hidden = NO;
        [self jk_shadowWithColor:[UIColor lightGrayColor] offset:CGSizeMake(1.2, 1.2) opacity:0.2 radius:0.3];
    }else if(style == USAlertTipBarStyle0){
        self.m_v0.hidden = NO;
        self.m_v1.hidden = YES;
        [self jk_shadowWithColor:[UIColor lightGrayColor] offset:CGSizeMake(2, 2) opacity:0.2 radius:0.3];
    }
    
    [self setNeedsLayout];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat h = self.bounds.size.height;
    CGFloat margin = 10;
 
    if (self.style == USAlertTipBarStyleDefault) {
        
        CGFloat tag_w = (h - margin * 2);
        
        [self.m_v0 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(margin);
            make.width.height.mas_equalTo(tag_w);
            make.centerY.mas_equalTo(self);
        }];
        
        [self.titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.m_v0.mas_right).mas_offset(margin);
            make.centerY.mas_equalTo(self);
            make.right.mas_equalTo(self.subLab.mas_left).mas_offset(-margin * 0.5);
        }];
        
        [self.m_v1 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_offset(-margin);
            make.top.bottom.mas_equalTo(self.m_v0);
            make.width.mas_equalTo(4);
        }];
        [self.subLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.m_v1.mas_left).mas_offset(-margin);
            make.centerY.mas_equalTo(self);
            make.width.mas_lessThanOrEqualTo(120);
        }];
        
        self.m_v0.layer.cornerRadius = tag_w * 0.5;
        self.m_v1.layer.cornerRadius = 4 * 0.5;
        self.layer.maskedCorners = kCALayerMinXMinYCorner|kCALayerMinXMaxYCorner;
        self.layer.cornerRadius = h * 0.5;
        
    }else if (self.style == USAlertTipBarStyle0){
        
        [self.m_v0 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(margin);
            make.top.mas_offset(margin);
            make.bottom.mas_offset(-margin);
            make.width.mas_equalTo(4);
        }];
        
        [self.titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.m_v0.mas_right).mas_offset(margin);
            make.centerY.mas_equalTo(self);
        }];
        
        [self.m_v1 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.mas_offset(0);
            make.width.mas_equalTo(1);
        }];
        [self.subLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.m_v1.mas_left).mas_offset(-margin);
            make.centerY.mas_equalTo(self);
        }];
        
        self.m_v0.layer.cornerRadius = 2;
        self.m_v0.layer.cornerRadius = 0;
        self.layer.cornerRadius = 0;
        
    }
    
    
}





@end
